package com.lwc.cfdns.controller.admin.system;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.lwc.cfdns.constants.ConstantsUrl;
import com.lwc.cfdns.pojo.bo.system.StationBO;
import com.lwc.cfdns.pojo.dto.ValidGroup;
import com.lwc.cfdns.pojo.dto.system.StationDTO;
import com.lwc.cfdns.pojo.vo.system.StationVO;
import com.lwc.cfdns.service.impl.SystemStationServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.validation.constraints.NotBlank;
import javax.validation.constraints.NotNull;
import java.util.Map;

/**
 * 岗位接口
 *
 * @author luwc
 * @title StationController
 * @description
 * @time 2023/5/26 16:13:28
 * @version: 1.0
 */
@RestController
@RequestMapping(ConstantsUrl.ADMIN + "/system")
public class StationController {
    @Autowired
    private SystemStationServiceImpl systemStationService;

    /**
     * 创建
     *
     * @param stationDTO
     * @return Map<String, Object>
     * @throws
     * @version 1.0.0
     * @author luwc
     * @time 2023/5/26 16:19:15
     */
    @PreAuthorize("hasAnyAuthority('system:station:create')")
    @PostMapping("/station")
    public Map<String, Object> create(@Validated(ValidGroup.Create.class) @RequestBody StationDTO stationDTO) {
        return systemStationService.create(stationDTO);
    }

    /**
     * 详情
     *
     * @param id
     * @return StationVO
     * @throws
     * @version 1.0.0
     * @author luwc
     * @time 2023/5/26 16:23:50
     */
    @PreAuthorize("hasAnyAuthority('system:station:view')")
    @GetMapping("/station/{id}")
    public StationVO view(@PathVariable("id") @NotNull(message = "岗位ID不能为空!") Long id) {
        return systemStationService.view(id);
    }

    /**
     * 修改
     *
     * @param stationDTO
     * @param id
     * @return Map<String, Object>
     * @throws
     * @version 1.0.0
     * @author luwc
     * @time 2023/5/26 16:26:26
     */
    @PreAuthorize("hasAnyAuthority('system:station:update')")
    @PutMapping("/station/{id}")
    public Map<String, Object> update(@Validated(ValidGroup.Update.class) @RequestBody StationDTO stationDTO, @PathVariable("id") @NotNull(message = "岗位ID不能为空") Long id) {
        return systemStationService.update(id, stationDTO);
    }

    /**
     * 删除
     *
     * @param id
     * @return Map<String, Object>
     * @throws
     * @version 1.0.0
     * @author luwc
     * @time 2023/5/26 16:27:51
     */
    @PreAuthorize("hasAnyAuthority('system:station:delete')")
    @DeleteMapping("/station/{ids}")
    public Map<String, Object> delete(@PathVariable("ids") @NotBlank(message = "岗位ID不能为空!") String ids) {
        return systemStationService.delete(ids);
    }

    /**
     * 列表
     *
     * @param
     * @return IPage<StationVO>
     * @throws
     * @version 1.0.0
     * @author luwc
     * @time 2023/5/26 16:29:15
     */
    @PreAuthorize("hasAnyAuthority('system:station:lists')")
    @GetMapping("/station")
    public IPage<StationVO> lists(StationBO stationBO) {
        return systemStationService.lists(stationBO);
    }
}
